package
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	[SWF(frameRate="60",width="800", height="800")]
	public class Main extends Sprite
	{
		
		private var partie:Tetris2D;
		
		private var next:NextBlock;
		
		public function Main()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);	
		}
		
		private function onAddedToStage(event:Event):void {
			
			partie = new Tetris2D(stage);	
			partie.addEventListener("blockChanged", blockChanged);
			this.addChild(partie);
			
			next = new NextBlock(partie);
			next.x = partie.width + 40;
			addChild(next);
			
			var tweenerButton:Sprite = new Sprite();
			tweenerButton.graphics.beginFill(0x45845A);
			tweenerButton.graphics.drawEllipse(0,0,100,45);
			tweenerButton.graphics.endFill();
			tweenerButton.buttonMode = true;
			tweenerButton.mouseChildren = false;
			var tf:TextField = new TextField();
			tf.selectable = false;
			tf.text = "use tweener";
			tf.autoSize = TextFieldAutoSize.CENTER;
			tf.x = tweenerButton.width/2 - tf.width/2;
			tf.y = tweenerButton.height/2 - tf.height/2 - 2;
			tweenerButton.addChild(tf);
			
			tweenerButton.addEventListener(MouseEvent.CLICK, switchTweener);
			
			tweenerButton.x = partie.width + 80;
			tweenerButton.y = 150;
			addChild(tweenerButton);
			
			
		}
		
		private function blockChanged(event:Event):void {
			next.gb = partie.nextGBlock;
		}
		
		private function switchTweener(event:MouseEvent):void {
			partie.USER_TWEENER = !partie.USER_TWEENER;
		}
		
	}
}